package engine.input;

import java.util.LinkedList;

public class KeyboardManager {
	public KeyboardManager() {
		_Handlers = new LinkedList<KeyboardHandler_I>();
	}
	public void add(KeyboardHandler_I handler) {
		if(handler != null) {
			_Handlers.push(handler);
		}
	}
	public void remove(KeyboardHandler_I handler) {
		_Handlers.remove(handler);
	}
	public void sendMessage(KeyQueue_I queue) {
		if(_Handlers.isEmpty() == true) {
			queue.clear();
			return;
		}
		KeyInfo keyInfo = queue.pop();
		while(keyInfo != null) {
			for(KeyboardHandler_I handler : _Handlers) {
				if(handler.handleKeyboard(keyInfo) == true) {
					break;
				}
			}
			keyInfo = queue.pop();
		} 
	}
	
	private LinkedList<KeyboardHandler_I> _Handlers;
}
